<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>保质期计算工具</title>
    <style>
      * {
        box-sizing: border-box;
        margin: 0;
        padding: 0;
        font-family: 'SF Pro Display', 'PingFang SC', 'Helvetica Neue', Arial,
          sans-serif;
      }

      :root {
        --primary-bg: #e6e7ee;
        --secondary-bg: #ffffff;
        --shadow-light: #ffffff;
        --shadow-dark: #d1d9e6;
        --accent-color: #667eea;
        --accent-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        --success-color: #4ecdc4;
        --danger-color: #ff6b6b;
        --warning-color: #feca57;
        --text-primary: #2d3748;
        --text-secondary: #718096;
        --glass-bg: rgba(255, 255, 255, 0.25);
        --glass-border: rgba(255, 255, 255, 0.18);
      }

      body {
        background: var(--primary-bg);
        color: var(--text-primary);
        min-height: 100vh;
        padding: 20px;
        display: flex;
        flex-direction: column;
        align-items: center;
        transition: all 0.3s ease;
        animation: pageLoad 0.8s ease;
      }

      @keyframes pageLoad {
        from {
          opacity: 0;
          transform: translateY(20px);
        }
        to {
          opacity: 1;
          transform: translateY(0);
        }
      }

      .container {
        width: 100%;
        max-width: 1200px;
        background: var(--primary-bg);
        border-radius: 30px;
        padding: 40px;
        box-shadow: 20px 20px 60px var(--shadow-dark),
          -20px -20px 60px var(--shadow-light);
        margin-top: 20px;
        transition: all 0.3s ease;
        animation: containerFloat 1s ease 0.2s both;
      }

      @keyframes containerFloat {
        from {
          opacity: 0;
          transform: translateY(30px) scale(0.95);
        }
        to {
          opacity: 1;
          transform: translateY(0) scale(1);
        }
      }

      .container:hover {
        box-shadow: 25px 25px 70px var(--shadow-dark),
          -25px -25px 70px var(--shadow-light);
      }

      header {
        text-align: center;
        margin-bottom: 40px;
        padding: 30px;
        background: var(--primary-bg);
        border-radius: 25px;
        box-shadow: 10px 10px 20px var(--shadow-dark),
          -10px -10px 20px var(--shadow-light);
        animation: headerSlide 0.8s ease 0.4s both;
      }

      @keyframes headerSlide {
        from {
          opacity: 0;
          transform: translateY(-30px);
        }
        to {
          opacity: 1;
          transform: translateY(0);
        }
      }

      h1 {
        font-size: 3.2rem;
        margin-bottom: 15px;
        background: var(--accent-gradient);
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
        background-clip: text;
        font-weight: 700;
        animation: titleGlow 3s ease-in-out infinite alternate;
      }

      @keyframes titleGlow {
        from {
          filter: brightness(1);
        }
        to {
          filter: brightness(1.2);
        }
      }

      .subtitle {
        font-size: 1.3rem;
        color: var(--text-secondary);
        margin-bottom: 30px;
        font-weight: 500;
      }

      .panels {
        display: flex;
        gap: 30px;
        margin-bottom: 40px;
        animation: panelsSlide 0.8s ease 0.6s both;
      }

      @keyframes panelsSlide {
        from {
          opacity: 0;
          transform: translateX(-20px);
        }
        to {
          opacity: 1;
          transform: translateX(0);
        }
      }

      .panel {
        flex: 1;
        background: var(--primary-bg);
        border-radius: 25px;
        padding: 30px;
        box-shadow: 12px 12px 24px var(--shadow-dark),
          -12px -12px 24px var(--shadow-light);
        transition: all 0.3s ease;
        position: relative;
        overflow: hidden;
      }

      .panel::before {
        content: '';
        position: absolute;
        top: 0;
        left: -100%;
        width: 100%;
        height: 100%;
        background: linear-gradient(
          90deg,
          transparent,
          rgba(255, 255, 255, 0.1),
          transparent
        );
        transition: left 0.8s;
      }

      .panel:hover::before {
        left: 100%;
      }

      .panel:hover {
        transform: translateY(-5px);
        box-shadow: 16px 16px 32px var(--shadow-dark),
          -16px -16px 32px var(--shadow-light);
      }

      .panel-title {
        font-size: 1.6rem;
        margin-bottom: 25px;
        color: var(--accent-color);
        display: flex;
        align-items: center;
        font-weight: 600;
      }

      .panel-title::before {
        content: attr(data-icon);
        margin-right: 12px;
        font-size: 1.8rem;
        animation: iconBounce 2s ease-in-out infinite;
      }

      @keyframes iconBounce {
        0%,
        100% {
          transform: scale(1);
        }
        50% {
          transform: scale(1.1);
        }
      }

      .form-group {
        margin-bottom: 25px;
      }

      label {
        display: block;
        margin-bottom: 10px;
        color: var(--text-secondary);
        font-weight: 500;
        font-size: 0.95rem;
      }

      input,
      select {
        width: 100%;
        padding: 14px 18px;
        background: var(--primary-bg);
        border: none;
        border-radius: 15px;
        color: var(--text-primary);
        font-size: 1rem;
        font-weight: 500;
        box-shadow: inset 6px 6px 12px var(--shadow-dark),
          inset -6px -6px 12px var(--shadow-light);
        transition: all 0.3s ease;
      }

      input:focus,
      select:focus {
        outline: none;
        box-shadow: inset 8px 8px 16px var(--shadow-dark),
          inset -8px -8px 16px var(--shadow-light),
          0 0 0 3px rgba(102, 126, 234, 0.2);
      }

      button {
        background: var(--primary-bg);
        color: var(--text-primary);
        border: none;
        padding: 14px 28px;
        border-radius: 15px;
        cursor: pointer;
        font-weight: 600;
        transition: all 0.3s ease;
        font-size: 1rem;
        flex-shrink: 0;
        box-shadow: 8px 8px 16px var(--shadow-dark),
          -8px -8px 16px var(--shadow-light);
        position: relative;
        overflow: hidden;
      }

      button::before {
        content: '';
        position: absolute;
        top: 0;
        left: -100%;
        width: 100%;
        height: 100%;
        background: linear-gradient(
          90deg,
          transparent,
          rgba(255, 255, 255, 0.2),
          transparent
        );
        transition: left 0.5s;
      }

      button:hover::before {
        left: 100%;
      }

      button:hover {
        transform: translateY(-3px);
        box-shadow: 12px 12px 24px var(--shadow-dark),
          -12px -12px 24px var(--shadow-light);
      }

      button:active {
        transform: translateY(0);
        box-shadow: inset 6px 6px 12px var(--shadow-dark),
          inset -6px -6px 12px var(--shadow-light);
      }

      .btn-primary {
        background: var(--accent-gradient);
        color: white;
        padding: 16px 32px;
        font-size: 1.1rem;
        box-shadow: 8px 8px 16px var(--shadow-dark),
          -8px -8px 16px var(--shadow-light),
          inset 0 1px 0 rgba(255, 255, 255, 0.2);
        width: 100%;
        margin-top: 20px;
      }

      .btn-primary:hover {
        box-shadow: 12px 12px 24px var(--shadow-dark),
          -12px -12px 24px var(--shadow-light),
          inset 0 1px 0 rgba(255, 255, 255, 0.2),
          0 0 30px rgba(102, 126, 234, 0.3);
      }

      .result-panel {
        background: var(--primary-bg);
        border-radius: 25px;
        padding: 30px;
        margin-top: 30px;
        box-shadow: 12px 12px 24px var(--shadow-dark),
          -12px -12px 24px var(--shadow-light);
        text-align: center;
        animation: resultSlide 0.8s ease 0.8s both;
        display: none;
      }

      @keyframes resultSlide {
        from {
          opacity: 0;
          transform: translateY(30px);
        }
        to {
          opacity: 1;
          transform: translateY(0);
        }
      }

      .result-title {
        font-size: 1.8rem;
        margin-bottom: 20px;
        color: var(--accent-color);
        font-weight: 600;
      }

      .result-item {
        background: var(--primary-bg);
        border-radius: 20px;
        padding: 20px;
        margin-bottom: 15px;
        box-shadow: 8px 8px 16px var(--shadow-dark),
          -8px -8px 16px var(--shadow-light);
        display: flex;
        justify-content: space-between;
        align-items: center;
        transition: all 0.3s ease;
      }

      .result-item:hover {
        transform: translateY(-2px);
        box-shadow: 10px 10px 20px var(--shadow-dark),
          -10px -10px 20px var(--shadow-light);
      }

      .result-label {
        font-weight: 600;
        color: var(--text-secondary);
        font-size: 1rem;
      }

      .result-value {
        font-weight: 700;
        font-size: 1.2rem;
        color: var(--text-primary);
      }

      .status-indicator {
        padding: 8px 16px;
        border-radius: 20px;
        font-weight: 600;
        font-size: 0.9rem;
        margin-left: 15px;
      }

      .status-fresh {
        background: linear-gradient(135deg, var(--success-color) 0%, #44a08d 100%);
        color: white;
      }

      .status-warning {
        background: linear-gradient(135deg, var(--warning-color) 0%, #ff9ff3 100%);
        color: white;
      }

      .status-expired {
        background: linear-gradient(135deg, var(--danger-color) 0%, #ee5a24 100%);
        color: white;
      }

      .quick-actions {
        display: flex;
        gap: 15px;
        margin-top: 25px;
        flex-wrap: wrap;
      }

      .quick-btn {
        flex: 1;
        min-width: 120px;
        padding: 12px 20px;
        font-size: 0.9rem;
        background: var(--primary-bg);
        box-shadow: 6px 6px 12px var(--shadow-dark),
          -6px -6px 12px var(--shadow-light);
      }

      .instructions {
        background: var(--primary-bg);
        border-radius: 25px;
        padding: 30px;
        margin-top: 40px;
        box-shadow: 10px 10px 20px var(--shadow-dark),
          -10px -10px 20px var(--shadow-light);
        animation: instructionsSlide 0.8s ease 1.4s both;
      }

      @keyframes instructionsSlide {
        from {
          opacity: 0;
          transform: translateY(30px);
        }
        to {
          opacity: 1;
          transform: translateY(0);
        }
      }

      .instructions h3 {
        color: var(--accent-color);
        margin-bottom: 20px;
        font-size: 1.4rem;
        font-weight: 600;
      }

      .instructions ol {
        padding-left: 25px;
        margin-bottom: 20px;
      }

      .instructions li {
        margin-bottom: 12px;
        line-height: 1.7;
        color: var(--text-secondary);
        font-weight: 500;
      }

      .instructions p {
        color: var(--text-secondary);
        font-style: italic;
        font-weight: 500;
        padding: 15px;
        background: rgba(102, 126, 234, 0.1);
        border-radius: 15px;
        border-left: 4px solid var(--accent-color);
      }

      footer {
        margin-top: 40px;
        text-align: center;
        color: var(--text-secondary);
        font-size: 0.95rem;
        padding: 25px;
        background: var(--primary-bg);
        border-radius: 20px;
        box-shadow: 6px 6px 12px var(--shadow-dark),
          -6px -6px 12px var(--shadow-light);
        animation: footerFade 0.8s ease 1.6s both;
      }

      @keyframes footerFade {
        from {
          opacity: 0;
        }
        to {
          opacity: 1;
        }
      }

      /* 响应式设计 */
      @media (max-width: 1024px) {
        .container {
          padding: 30px;
          margin: 10px;
        }

        .panels {
          flex-direction: column;
        }

        h1 {
          font-size: 2.5rem;
        }

        .subtitle {
          font-size: 1.1rem;
        }
      }

      @media (max-width: 768px) {
        .container {
          padding: 20px;
        }

        .quick-actions {
          flex-direction: column;
        }

        .result-item {
          flex-direction: column;
          text-align: center;
          gap: 10px;
        }

        h1 {
          font-size: 2rem;
        }
      }
    </style>
  </head>
  <body>
    <div class="container">
      <header>
        <h1>📅 保质期计算工具</h1>
        <p class="subtitle">智能计算食品保质期，守护您的健康安全</p>
      </header>

      <div class="panels">
        <!-- 输入面板 -->
        <div class="panel">
          <div class="panel-title" data-icon="📝">信息输入</div>
          
          <div class="form-group">
            <label for="productName">产品名称</label>
            <input type="text" id="productName" placeholder="请输入产品名称（可选）" />
          </div>

          <div class="form-group">
            <label for="productionDate">生产日期</label>
            <input type="date" id="productionDate" />
          </div>

          <div class="form-group">
            <label for="shelfLifeDays">保质期（天数）</label>
            <input type="number" id="shelfLifeDays" min="1" placeholder="请输入保质期天数" />
          </div>

          <div class="form-group">
            <label for="shelfLifeType">保质期类型</label>
            <select id="shelfLifeType">
              <option value="days">天</option>
              <option value="months">月</option>
              <option value="years">年</option>
            </select>
          </div>

          <button class="btn-primary" id="calculateBtn">🧮 计算保质期</button>
        </div>

        <!-- 快捷设置面板 -->
        <div class="panel">
          <div class="panel-title" data-icon="⚡">快捷设置</div>
          
          <div class="quick-actions">
            <button class="quick-btn" onclick="setQuickShelfLife(1)">1天</button>
            <button class="quick-btn" onclick="setQuickShelfLife(7)">1周</button>
            <button class="quick-btn" onclick="setQuickShelfLife(30)">1个月</button>
            <button class="quick-btn" onclick="setQuickShelfLife(90)">3个月</button>
            <button class="quick-btn" onclick="setQuickShelfLife(180)">6个月</button>
            <button class="quick-btn" onclick="setQuickShelfLife(365)">1年</button>
            <button class="quick-btn" onclick="setQuickShelfLife(730)">2年</button>
            <button class="quick-btn" onclick="setQuickShelfLife(1095)">3年</button>
          </div>

          <div class="form-group" style="margin-top: 30px;">
            <label>常见食品保质期参考</label>
            <div style="background: rgba(102, 126, 234, 0.1); padding: 15px; border-radius: 15px; font-size: 0.9rem; color: var(--text-secondary);">
              🥛 牛奶: 3-7天<br>
              🍞 面包: 3-5天<br>
              🥚 鸡蛋: 30-45天<br>
              🧀 奶酪: 30-90天<br>
              🍖 冷冻肉类: 180-365天<br>
              🥫 罐头食品: 1-3年
            </div>
          </div>
        </div>
      </div>

      <!-- 结果显示面板 -->
      <div class="result-panel" id="resultPanel">
        <div class="result-title">📊 计算结果</div>
        
        <div class="result-item">
          <span class="result-label">产品名称</span>
          <span class="result-value" id="resultProductName">-</span>
        </div>

        <div class="result-item">
          <span class="result-label">生产日期</span>
          <span class="result-value" id="resultProductionDate">-</span>
        </div>

        <div class="result-item">
          <span class="result-label">保质期</span>
          <span class="result-value" id="resultShelfLife">-</span>
        </div>

        <div class="result-item">
          <span class="result-label">到期日期</span>
          <span class="result-value" id="resultExpiryDate">-</span>
        </div>

        <div class="result-item">
          <span class="result-label">剩余天数</span>
          <div style="display: flex; align-items: center;">
            <span class="result-value" id="resultRemainingDays">-</span>
            <span class="status-indicator" id="statusIndicator">-</span>
          </div>
        </div>

        <div class="quick-actions">
          <button class="quick-btn" onclick="resetForm()">🔄 重新计算</button>
          <button class="quick-btn" onclick="setToday()">📅 设为今天</button>
          <button class="quick-btn" onclick="copyResult()">📋 复制结果</button>
        </div>
      </div>

      <!-- 使用说明 -->
      <div class="instructions">
        <h3>📖 使用说明</h3>
        <ol>
          <li>输入产品名称（可选）和生产日期</li>
          <li>设置保质期天数或使用快捷按钮</li>
          <li>点击"计算保质期"查看详细结果</li>
          <li>根据剩余天数判断产品新鲜度状态</li>
        </ol>
        <p>
          💡 提示：绿色表示新鲜，黄色表示临近过期，红色表示已过期。建议在保质期内尽快食用。
        </p>
      </div>

      <footer>
        <p>🛡️ 保质期计算工具 | 🌐 守护您的饮食安全</p>
      </footer>
    </div>

    <script>
      // 设置今天的日期为默认生产日期
      function setToday() {
        const today = new Date().toISOString().split('T')[0];
        document.getElementById('productionDate').value = today;
      }

      // 快捷设置保质期
      function setQuickShelfLife(days) {
        document.getElementById('shelfLifeDays').value = days;
        document.getElementById('shelfLifeType').value = 'days';
      }

      // 计算保质期
      function calculateShelfLife() {
        const productName = document.getElementById('productName').value || '未命名产品';
        const productionDate = document.getElementById('productionDate').value;
        const shelfLifeDays = parseInt(document.getElementById('shelfLifeDays').value);
        const shelfLifeType = document.getElementById('shelfLifeType').value;

        if (!productionDate || !shelfLifeDays) {
          alert('请填写完整的生产日期和保质期信息！');
          return;
        }

        // 转换保质期为天数
        let totalDays = shelfLifeDays;
        if (shelfLifeType === 'months') {
          totalDays = shelfLifeDays * 30;
        } else if (shelfLifeType === 'years') {
          totalDays = shelfLifeDays * 365;
        }

        // 计算到期日期
        const prodDate = new Date(productionDate);
        const expiryDate = new Date(prodDate);
        expiryDate.setDate(prodDate.getDate() + totalDays);

        // 计算剩余天数
        const today = new Date();
        const remainingDays = Math.ceil((expiryDate - today) / (1000 * 60 * 60 * 24));

        // 显示结果
        displayResults({
          productName,
          productionDate: formatDate(prodDate),
          shelfLife: `${shelfLifeDays} ${getShelfLifeTypeText(shelfLifeType)}`,
          expiryDate: formatDate(expiryDate),
          remainingDays
        });
      }

      // 显示计算结果
      function displayResults(data) {
        document.getElementById('resultProductName').textContent = data.productName;
        document.getElementById('resultProductionDate').textContent = data.productionDate;
        document.getElementById('resultShelfLife').textContent = data.shelfLife;
        document.getElementById('resultExpiryDate').textContent = data.expiryDate;
        document.getElementById('resultRemainingDays').textContent = `${data.remainingDays} 天`;

        // 设置状态指示器
        const statusIndicator = document.getElementById('statusIndicator');
        if (data.remainingDays > 7) {
          statusIndicator.textContent = '新鲜';
          statusIndicator.className = 'status-indicator status-fresh';
        } else if (data.remainingDays > 0) {
          statusIndicator.textContent = '临期';
          statusIndicator.className = 'status-indicator status-warning';
        } else {
          statusIndicator.textContent = '过期';
          statusIndicator.className = 'status-indicator status-expired';
        }

        // 显示结果面板
        document.getElementById('resultPanel').style.display = 'block';
      }

      // 格式化日期
      function formatDate(date) {
        return date.toLocaleDateString('zh-CN', {
          year: 'numeric',
          month: '2-digit',
          day: '2-digit'
        });
      }

      // 获取保质期类型文本
      function getShelfLifeTypeText(type) {
        switch (type) {
          case 'days': return '天';
          case 'months': return '个月';
          case 'years': return '年';
          default: return '天';
        }
      }

      // 重置表单
      function resetForm() {
        document.getElementById('productName').value = '';
        document.getElementById('productionDate').value = '';
        document.getElementById('shelfLifeDays').value = '';
        document.getElementById('shelfLifeType').value = 'days';
        document.getElementById('resultPanel').style.display = 'none';
      }

      // 复制结果
      function copyResult() {
        const productName = document.getElementById('resultProductName').textContent;
        const productionDate = document.getElementById('resultProductionDate').textContent;
        const shelfLife = document.getElementById('resultShelfLife').textContent;
        const expiryDate = document.getElementById('resultExpiryDate').textContent;
        const remainingDays = document.getElementById('resultRemainingDays').textContent;
        const status = document.getElementById('statusIndicator').textContent;

        const result = `产品名称: ${productName}\n生产日期: ${productionDate}\n保质期: ${shelfLife}\n到期日期: ${expiryDate}\n剩余天数: ${remainingDays}\n状态: ${status}`;

        navigator.clipboard.writeText(result).then(() => {
          alert('结果已复制到剪贴板！');
        }).catch(() => {
          alert('复制失败，请手动复制结果。');
        });
      }

      // 绑定事件
      document.getElementById('calculateBtn').addEventListener('click', calculateShelfLife);

      // 页面加载时设置今天的日期
      window.addEventListener('load', () => {
        setToday();
      });
    </script>
  </body>
</html>